proc unban {nick handle chan otbn1 host} {
  global botnick home bcast

  if {$otbn1 == ""} {
    puthelp "NOTICE $nick :\0034ERROR - Invalid Syntax - Should Be - (/msg) $botnick unban (#channel) <mask>"
    return 0
  # is the bot opped?
  } elseif {![botisop $chan]} {
    puthelp "NOTICE $nick :\0034ERROR - Bot dosen't have op status (+o) on $chan"
    return 0
  }

  if {[isban $otbn1]} {
    if {[matchattr $handle o]} {
      putlog "!$nick ($host)! unban $otbn1"
      killban $otbn1
      putquick "NOTICE $nick :\0033Removed ban from channel partition."

      if {$bcast == "1"} {
        puthelp "PRIVMSG $home :Calling for unban request for \002$otbn1\002 (Requested By: \002$nick\002 ($host))"
      }  

      return 0
    } else {
      puthelp "NOTICE $nick :\0034ERROR - Unable To Execute Command - Not Enough Permissions - Permission Denied."
      return 0
    } 
  }

  if {[isban $otbn1 $chan]} {
    putlog "!$nick ($host)! unban $chan $otbn1"
    killchanban $chan $otbn1
    putquick "NOTICE $nick :\0033Removed ban \0034\002$otbn1\002\0033 from channel record '\0034$chan\0033'"
    puthelp "NOTICE $chan :\0033Removed ban \0034\002$otbn1\002\0033 from this channel.  Ban Numbers have been updated."

    if {$bcast == "1"} {
      puthelp "PRIVMSG $home :Calling for unban request for \002$otbn1\002 in $chan (Requested By: \002$nick\002 ($host))"
    }
  
    return 0
  }

  if {[ischanban $otbn1 $chan]} {
    putlog "!$nick ($host)! unban $chan $otbn1"
    putquick "MODE $chan -b $otbn1"
    putquick "NOTICE $nick :\0033Removed ban \0034\002$otbn1\002\0033 from channel record '\0034$chan\0033'"
    puthelp "NOTICE $chan :\0033Removed ban \0034\002$otbn1\002\0033 from this channel.  Ban Numbers have been updated."

    if {$bcast == "1"} {
      puthelp "PRIVMSG $home :Calling for unban request for \002$otbn1\002 in $chan (Requested By: \002$nick\002 ($host))"
    }

    return 0
  }

  # Usually by now all possible bans would have been exhausted, now allow for numeric unbans
  # ... Added in X-Bot 2004
  ##########################################################################################
  # Process ban from banlist
  # ------------------------
  set counter 1
  foreach newban [banlist $chan] {
    set mask [lindex $newban 0]
    set reason [lindex $newban 1]
    set expire [lindex $newban 2]
    set added [lindex $newban 3]
    set setter [lindex $newban 5]
    set dateexpired [ctime $expire]
    set dateadded [ctime $added]

    # if the parameter passed to this function matches the counter value, the user wants that
    #   ban removed
    if { $otbn1 == $counter } {
      unban $nick $handle $chan $mask $host
      return 0
    }

    incr counter
  }


  puthelp "NOTICE $nick :\0034ERROR - Could not find ban - \002$otbn1\002 could not be found in the channel partitions ban sector."
}









